package com.think.teaching.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.think.teaching.model.PaperQuestion;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * <p>
 * 试卷和试题关联 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface PaperQuestionMapper extends BaseMapper<PaperQuestion> {
//    @Select("<script>" +
//           "SELECT * " +
//            "FROM question " +
//            "WHERE question.id " +
//            "IN(" +
//            "SELECT paper_question.question_id " +
//            "FROM paper_question " +
//            "WHERE zone_id=#{id}) AND delflag=0"+
//           "</script>"
//    )
@Select("SELECT paper_question.id as PQ_id, question.* " +
        "FROM paper_question, question " +
        "WHERE paper_question.zone_id=#{id} AND " +
        "question.id = paper_question.question_id")
@Result(column = "id",property = "id")
@Result(column = "id",property = "selections",one = @One(select = "com" +
        ".think.teaching.mapper.QuestionMapper.GetQuestionSelections",fetchType = FetchType.EAGER))
    List<LinkedHashMap<String,Object>> GetPaperQuestionByZone(Integer id);



}
